package com.libc.yygh.common.aspect;

import com.libc.yygh.common.LoggerUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * *
 * Created with Description:
 *
 * @fileRelativePath: MonitorCtrlRunAspect.java
 * @Date: Created on 2022/4/12  16:01  <br>
 * @author: LiBencheng <br>
 * @version: 1.0 <br>
 */
// @Component //将当前类注入到Spring容器内
@Aspect //表明是一个切面类
public class MonitorCtrlRunAspect
{
    /** 日志調試h */
    // Boolean isDebug = Boolean.FALSE;
    public static Boolean isDebug = Boolean.TRUE;
    // Pointcut 切入点
    // com.gameley.dmgtpf.*.controller

    /************************************************************* <br>
     *
     *说明:定义切入点，切入点为com.xisoft.hr.controller下的所有函数 <br>
     *
     * @Description   <br>
     * @Date Created on 2021/10/19  9:57  <br>
     * @Param [] <br>
     * @return void  <br>
     * @Author LIBENCHENG
     * @version 1.0 <br>
     ************************************************************* <br>
     */
    @Pointcut ("execution(public * com.xisoft.hr.controller(..))")
    public void logAspect( )
    {
    }

    @Around ("logAspect()")
    public Object deAround(ProceedingJoinPoint joinPoint) throws Throwable
    {
        LoggerUtil.debug(isDebug, "1、deAround");
        return joinPoint.proceed();
    }

    @Before ("logAspect()")
    public void doBefore(JoinPoint joinPoint)
    { LoggerUtil.debug(isDebug, "2、doBefore"); }

    @AfterReturning ("logAspect()")
    public void doAfterReturning(JoinPoint joinPoint)
    { LoggerUtil.debug(isDebug, "3、doAfterReturning"); }

    @After ("logAspect()")
    public void doAfter(JoinPoint joinPoint)
    { LoggerUtil.debug(isDebug, "4、doAfter"); }

    @AfterThrowing (pointcut = "logAspect()", throwing = "e")
    public void doAfterThrowing(JoinPoint point, Throwable e)
    { LoggerUtil.debug(isDebug, "2.5、deAfterThrowing"); }

    /**
     * 获取注解中对方法的描述信息 用于Controller层注解
     *
     * @param joinPoint 切点
     * @return 方法描述
     * @throws Exception
     */
    @SuppressWarnings ("rawtypes")
    public Map< String,Object > getControllerMethodDescription(JoinPoint joinPoint) throws Exception
    {
        Map< String,Object > map = new HashMap< String,Object >();
        String targetName = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        Object[] arguments = joinPoint.getArgs();
        Class targetClass = Class.forName(targetName);
        Method[] methods = targetClass.getMethods();

        return map;
    }

}
